﻿<Window x:Class="SongTagger.UI.Wpf.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
        xmlns:viewModel="clr-namespace:SongTagger.UI.Wpf"
        xmlns:gong="clr-namespace:GongSolutions.Wpf.DragDrop;assembly=GongSolutions.Wpf.DragDrop"
        xmlns:metroControls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
        mc:Ignorable="d"
        d:DataContext="{d:DesignInstance IsDesignTimeCreatable=True, Type=viewModel:MainWindowViewModelDesignData}"
        Title="{Binding WindowTitle}" Height="650" Width="850" 
        ResizeMode="CanResizeWithGrip" MinWidth="700" MinHeight="450"
        Icon="View/Images/logo.png"
        >
    <Window.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="View/DataTemplates.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
        
    </Window.Resources>
    <Window.TaskbarItemInfo>
        <TaskbarItemInfo ProgressState="{Binding IsWorkspaceBusy, Converter={StaticResource TaskBarStatusConverter}}"/>
    </Window.TaskbarItemInfo>
    <Grid ShowGridLines="False" Name="songtagger">
        <Grid.Style>
            <Style TargetType="Grid">
                <Style.Triggers>
                    <DataTrigger Binding="{Binding Error, Converter={StaticResource NullChecker}}" Value="False">
                        <Setter Property="Opacity" Value="0.7"/>
                    </DataTrigger>
                    <DataTrigger Binding="{Binding Error, Converter={StaticResource NullChecker}}" Value="True">
                        <Setter Property="Opacity" Value="1.0"/>
                    </DataTrigger>
                </Style.Triggers>
            </Style>
        </Grid.Style>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="2*"/>
            <ColumnDefinition Width="9*"/>
        </Grid.ColumnDefinitions>
        <Grid Grid.Column="0" Name="controller" KeyboardNavigation.IsTabStop="True">
            <Grid.RowDefinitions>
                <RowDefinition Height="100"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>
            <Grid.Resources>
                <viewModel:CartDataTemplateSelector x:Key="cartTemplateSelector"
                                                        NonVisibleTemplate="{StaticResource nonVisibleTemplate}"
                                                        DefaultDataTemplate="{StaticResource defaultCartTemplate}"/>
            </Grid.Resources>
            <Image Grid.Row="0" Source="View/Images/logo.png" Width="86" Style="{StaticResource Shadow}"/>
            <ContentControl Grid.Row="1" Margin="10,50"
                                HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
                                ContentTemplateSelector="{StaticResource cartTemplateSelector}"
                                Content="{Binding Cart}"
                                AllowDrop="True"
                                gong:DragDrop.IsDropTarget="True"
                                gong:DragDrop.DropHandler="{Binding Cart}"
                                gong:DragDrop.DragAdornerTemplate="{StaticResource entityTemplate}"/>

        </Grid>
        <Grid Grid.Column="1" Name="workspace" KeyboardNavigation.IsTabStop="False" FocusManager.IsFocusScope="False">
            <Grid.Resources>
                <viewModel:WorkspaceDataTemplateSelector x:Key="workspaceSelector"
                                                             SearchArtistDataTemplate="{StaticResource searchDataTemplate}"
                                                             MarketDataTemplate="{StaticResource marketDataTemplate}"
                                                             VirtualReleaseDataTemplate="{StaticResource virtualReleaseTemplate}"
                                                             />
            </Grid.Resources>
            <ContentControl Content="{Binding Workspace}" ContentTemplateSelector="{StaticResource workspaceSelector}"/>
            <Border Background="Transparent" Height="64" Width="384" VerticalAlignment="Bottom" 
                    BorderBrush="LimeGreen" BorderThickness="1"
                    Visibility="{Binding IsNotificationVisible, Converter={StaticResource Bool2Visibility}}">
                <Grid Margin="1">
                    <Rectangle Fill="Black" Opacity="0.85"/>
                    <Button HorizontalAlignment="Left" Width="64" Command="{Binding OpenFolder}">
                        <Button.Template>
                            <ControlTemplate>
                               <Image Width="64" Opacity="1.0">
                                    <Image.Source>
                                        <Binding Path="LastTaggedAlbum.Item3" IsAsync="True" Converter="{StaticResource ByteImageConverter}" TargetNullValue="View/Images/done.png"/>
                                    </Image.Source>
                                </Image>
                            </ControlTemplate>
                        </Button.Template>
                    </Button>

                    <StackPanel Margin="64,0,0,0" VerticalAlignment="Center">
                        <StackPanel.Resources>
                            <Style TargetType="TextBlock">
                                <Setter Property="FontSize" Value="14"/>
                                <Setter Property="Foreground" Value="White"/>
                            </Style>
                        </StackPanel.Resources>
                        <TextBlock Text="{Binding LastTaggedAlbum.Item1.Name}"/>
                        <TextBlock Text="{Binding LastTaggedAlbum.Item1.Artist.Name}"/>
                    </StackPanel>
                </Grid>
            </Border>

        </Grid>
        <Grid ColumnSpan="2" IsEnabled="{Binding IsWorkspaceBusy}"
                             Visibility="{Binding IsWorkspaceBusy, Converter={StaticResource Bool2Visibility}}">
            <Border Background="White" Opacity=".25"/>
            <Border Background="Black" Opacity=".75" Height="256">
                <StackPanel Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Center">
                    <metroControls:ProgressRing IsActive="True" Foreground="White"/>
                    <TextBlock Text="Please wait..." FontSize="32"  Margin="25,0,0,0" Foreground="White"/>
                </StackPanel>
            </Border>
        </Grid>
        <Grid ColumnSpan="2" IsEnabled="{Binding IsSettingsActive}"
                             Visibility="{Binding IsSettingsActive, Converter={StaticResource Bool2Visibility}}">
            <Grid.Resources>
                <viewModel:SettingDataTempalteSelector x:Key="settingDataTemplateSelector"
                                                       PathTemplate="{StaticResource pathSettingTempalte}"
                                                       SwitchTemplate="{StaticResource switchSettingTempalte}"
                                                       />
            </Grid.Resources>
            <Grid Background="White" Opacity=".90"/>
            <Grid VerticalAlignment="Top" HorizontalAlignment="Stretch" Margin="50,25">
                <Rectangle Fill="WhiteSmoke" Opacity=".9" Margin="0"/>
                <Rectangle Fill="LightGray" Opacity=".9" Margin="2"/>
                <Rectangle Fill="Gray" Opacity=".9" Margin="3"/>
                <Rectangle Fill="DarkGray" Opacity=".7" Margin="1"/>
                <StackPanel Background="White" Margin="4">
                    <Label Content="Settings" HorizontalAlignment="Center" FontSize="32"/>
                    <ItemsControl ItemsSource="{Binding Settings.Items}">
                        <ItemsControl.ItemTemplate>
                            <DataTemplate DataType="{x:Type viewModel:AbstractSettingViewModel}">
                                <Grid>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="256"/>
                                        <ColumnDefinition Width="*"/>
                                    </Grid.ColumnDefinitions>
                                    <Label Content="{Binding Title}" Grid.Column="0" HorizontalAlignment="Right" Margin="5"
                                           ContentStringFormat="{}{0}:" FontWeight="Bold"
                                           ToolTip="{Binding Hint}"/>
                                    <ContentControl Content="{Binding}" VerticalAlignment="Center"
                                                    ContentTemplateSelector="{StaticResource settingDataTemplateSelector}"
                                                    Grid.Column="1"/>
                                </Grid>
                            </DataTemplate>
                        </ItemsControl.ItemTemplate>
                    </ItemsControl>
                    <StackPanel Orientation="Horizontal" Margin="0,15" HorizontalAlignment="Center">
                        <StackPanel.Resources>
                            <Style TargetType="Button">
                                <Setter Property="Margin" Value="8,0"/>
                            </Style>
                        </StackPanel.Resources>
                        <Button Content="Reset" Width="60" Command="{Binding Settings.ResetToDefault}"/>
                        <Button Content="Apply" Width="60" Command="{Binding Settings.Apply}"/>
                    </StackPanel>
                </StackPanel>
            </Grid>
        </Grid>
    </Grid>
</Window>
